/*
 * @Author: heinan
 * @Date: 2021-07-14 16:33:27
 * @Last Modified by: heinan
 * @Last Modified time: 2021-07-15 16:58:22
 */
import React, { Component } from "react";
import { ROUTER_WHITELIST } from "@/config";
import { Redirect } from "react-router-dom";

export const withInterceptor = function (option = {}) {
  return function (WrapComponent) {
    return class extends Component {
      state = {
          
      }
      render() {
        const inWhiteList = ROUTER_WHITELIST.filter(
          (whiteList) => whiteList === this.props.location.pathname
        );
        return inWhiteList.length ? (
          <WrapComponent {...this.state}></WrapComponent>
        ) : (
          <Redirect
            from={this.props.location.pathname}
            to="/user/login"
          ></Redirect>
        );
      }
    };
  };
};
